package com.samsung.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.samsung.R;
import com.samsung.list.ItemView;
import com.samsung.list.ListItem;

public class ItemListAdapter extends BaseAdapter
{
	
	private Context context;
	private ArrayList<ListItem> list = new ArrayList<ListItem>();
	
	public ItemListAdapter(Context context, ArrayList<ListItem> list)
	{
		super();
		this.context = context;
		this.list = list;
	}

	public ArrayList<ListItem> getList()
	{
		return list;
	}

	public void setList(ArrayList<ListItem> list)
	{
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return list.size()	;
	}

	@Override
	public Object getItem(int position)
	{
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		// TODO Auto-generated method stub
		ItemView view;
		if(convertView == null)
			view = (ItemView) View.inflate(context, R.layout.listitem, null);
		else
			view = (ItemView) convertView;
		
		view.setItem(list.get(position));
		
		return view;
	}
	
	public void forceReload()
	{
		notifyDataSetInvalidated();
	}

}
